<%= form_for @order,
      :url => update_visible_order_url(@order),
      :remote => true,
      :method => :post do |f| %>
<div class="set_can_see">
  <div class="top">
    <div class="center">设置谁可以看到该单</div><div class="close" title="关闭">
      <%= link_to "×", close_can_see_order_url(@order), :remote => true, :method => :get %>
    </div>
  </div>
  <div class="content">
    <%= f.radio_button :visible_scope, :everyone %> <%= label :order, :visible_scope_everyone, t(:everyone) %><br/>
    <%= f.radio_button :visible_scope, :myself%> <%= label :order, :visible_scope_myself, t(:myself) %><br/>

    <%= f.radio_button :visible_scope, :groups %> <%= label :order, :visible_scope_groups, t(:groups)  %><br/>
      <div id="groups" <%= "style = 'display:block'" if @order.visible_scope == "groups"%>>
      <%Group.all.each do |group|%>
         <%= check_box_tag "group_ids[]", group.id, @order.groups.include?(group) , :id => "group_id#{group.id}", :class => "group", :onchange => "set_visible()" %>
         <%= label "group", "id#{group.id}", group.name, :class => @order.groups.include?(group)? "bold" : "" %><br/>
      <%end%>
      </div>

    <%= f.radio_button :visible_scope, :users %> <%= label :order, :visible_scope_users, t(:users) %><br/>
      <div id="users" <%= "style = 'display:block'" if @order.visible_scope == "users"%>>
      <%current_user.enterprise.users.each do |user|%>
          <%= check_box_tag "user_ids[]", user.id, @order.users.include?(user) , :id => "user_id#{user.id}", :class => "user", :onchange => "set_visible()" %>
          <%= label "user", "id#{user.id}", user.full_name, :class => @order.users.include?(user)? "bold" : "" %><br/>
      <%end%>
      </div>
   </div>
</div>
<script type="text/javascript" charset="utf-8">
  $(document).ready(function(){    
     $("#order_visible_scope_everyone").change(function(){
         $("#groups").hide(500);
         $("#users").hide(500);
        $("#edit_order_<%= @order.id%>").submit();
     });
     $("#order_visible_scope_myself").change(function(){
       $("#groups").hide(500);
       $("#users").hide(500);
        $("#edit_order_<%= @order.id%>").submit();
     });
     $("#order_visible_scope_groups").change(function(){
        if($(this).attr("checked") == "checked"){
           $("#groups").show(500);
           $("#users").hide(500);
        }else{
           $("#groups").hide(500);
        }
     });
     $("#order_visible_scope_users").change(function(){
        if($(this).attr("checked") == "checked"){
           $("#users").show(500);
           $("#groups").hide(500);
        }else{
           $("#users").hide(500);
        }
     });
  });
  var set_visible = function(){
     $("#edit_order_<%= @order.id%>").submit();//提交
  }
</script>
<%end%>